<?php
/**
 * Created by PhpStorm.
 * User: Hanson
 * Date: 2016/9/25
 * Time: 23:08
 */

namespace App\Repository;


use App\Model\Role;

class RoleRepository
{
    protected $role;

    public function __construct(Role $role)
    {
        $this->role = $role;
    }

    /**
     * 获取所有角色
     *
     * @return \Illuminate\Database\Eloquent\Collection|static[]
     */
    public function all()
    {
        return Role::all();
    }

    /**
     * 增加角色
     *
     * @param $name string 角色名
     * @param null $displayName string 角色
     * @param null $description string 角色描述
     * @return bool|\Illuminate\Database\Eloquent\Model
     */
    public function add($name, $displayName = null, $description = null)
    {

        if(!$name) return false;

        return Role::updateOrCreate(['name' => $name], ['display_name' => $displayName, 'description' => $description]);
    }

    public function delete($id)
    {
        return Role::destroy($id);
    }
}